import idCard from "./validateFields/idCard";

interface Params {
    value:string | boolean;
    message:any;
}

const isEmpty = (value:any) => {
    /* 允许验证为空 */
    if (value == "" || value == null || value === false) {
        return true;
    }
    return false
};

export default {
    name(data:Params){
        if(!isEmpty(data.value)){
            return data.message
        }
    },
    mobile(data:Params){
        const mobileReg = /^1[3-9]\d{9}$/;
        if (!mobileReg.test(<string>data.value)){
            return '请输入正确的手机号'
        }
        return ''
    },
    bankNo(data:Params){
        const numberReg = /^\d*$/;
        if (!numberReg.test(<string>data.value)){
            return '银行卡必须是数字'
        }
        return ''
    },
    idCard(data:Params){
        console.log(data.value)
        if(isEmpty(data.value)){
            return data.message
        }
        if(!idCard(data.value)){
            return "请输入正确的身份证"
        }
        return ""
    },
    password({}:Params){

    },
    required({value,message}:Params){
        console.log(value,50)
        if(isEmpty(value)){
            return message
        }else{
            return ''
        }
    }
}
